package com.ymatou.iapi.sellertrading.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellertrading.service.ModifyremarkCall;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.database.model.Ymt_O_OrderNoteHistory;
import com.ymttest.database.sqlwapper.modifyrecipientIMapper;

/**
 * Date:2017-01-11
 * @author chencan
 *
 */
public class Tc_modifyremark {
	private static ModifyremarkCall modifyremarkCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("业务说明：修改订单备注");
	}

	@Before
	public void caseUp() {
		modifyremarkCall = new ModifyremarkCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(modifyremarkCall.getOpurl());
	}
	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_modifyremark_001() {
		Logger.start(true, "修改备注信息");
		try {

			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			Logger.comment("前置数据准备结束");
			int iorderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int ibuyerId = placeOrderResp.getUserId();

			String remark = "测试";
			int noteflag = 1;

			Map<String, Object> map1 = new HashMap<String, Object>();
			map1.put("Remark", remark);
			map1.put("NoteFlag", noteflag);
			map1.put("OrderId", iorderId);

			JSONObject retBea = new ModifyremarkCall(ibuyerId, ibuyerId)
					.callAndGetReturnData(map1);
			Integer code = retBea.getInt("Code");
			String msg = retBea.getString("Msg");

			//更新订单备注信息后的SQL记录
			List<Ymt_O_OrderNoteHistory> ordernotes = new modifyrecipientIMapper()
					.selectiuserId(ibuyerId);
			Ymt_O_OrderNoteHistory first = ordernotes.get(0);
			String tent = first.getsContent();
			int user = first.getiUserId();
			int order = first.getiOrderId();

			Logger.verifyEquals(200, code, "code返回结果");
			Logger.verifyEquals("操作成功", msg, "描述");
			Logger.verifyEquals(remark, tent, "备注信息");
			Logger.verifyEquals(ibuyerId, user, "买手ID");
			Logger.verifyEquals(iorderId, order, "订单号");

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_modifyremark_002() {
		Logger.start(true, "修改备注信息--用户信息不存在");
		try {

			int sellerid = 3388883;
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			Logger.comment("前置数据准备结束");
			int iorderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int ibuyerId = placeOrderResp.getUserId();
			String remark = "测试测试测";
			int noteflag = 1;

			Map<String, Object> map1 = new HashMap<String, Object>();
			map1.put("Remark", remark);
			map1.put("NoteFlag", noteflag);
			map1.put("OrderId", iorderId);

			JSONObject retBea = new ModifyremarkCall(sellerid, ibuyerId)
					.callAndGetReturnData(map1);
			Integer code = retBea.getInt("Code");
			String msg = retBea.getString("Msg");

			Logger.verifyEquals(201, code, "code返回结果");
			System.out.println(msg);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_modifyremark_003() {
		Logger.start(true, "修改备注信息--订单号错误");
		try {

			int sellerid = 3388883;
			int iuserId = 3383;
			int orderid = 133333;
			String remark = "测试测试测";
			int noteflag = 1;

			Map<String, Object> map1 = new HashMap<String, Object>();
			map1.put("Remark", remark);
			map1.put("NoteFlag", noteflag);
			map1.put("OrderId", orderid);

			JSONObject retBea = new ModifyremarkCall(sellerid, iuserId)
					.callAndGetReturnData(map1);
			Integer code = retBea.getInt("Code");
			String msg = retBea.getString("Msg");

			Logger.verifyEquals(201, code, "code返回结果");
			System.out.println(msg);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_modifyremark_004() {
		Logger.start(true, "修改备注信息--订单和用户不对应");
		try {

			int sellerid = 3383;
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			Logger.comment("前置数据准备结束");
			int iorderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int ibuyerId = placeOrderResp.getUserId();
			String remark = "测试测试测";
			int noteflag = 1;

			Map<String, Object> map1 = new HashMap<String, Object>();
			map1.put("Remark", remark);
			map1.put("NoteFlag", noteflag);
			map1.put("OrderId", iorderId);

			JSONObject retBea = new ModifyremarkCall(sellerid, ibuyerId)
					.callAndGetReturnData(map1);
			Integer code = retBea.getInt("Code");
			String msg = retBea.getString("Msg");

			Logger.verifyEquals(201, code, "code返回结果");
			System.out.println(msg);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_modifyremark_005() {
		Logger.start(true, "修改备注信息--备注信息为空");
		try {

			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			Logger.comment("前置数据准备结束");
			int iorderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int ibuyerId = placeOrderResp.getUserId();
			String remark = " ";
			int noteflag = 1;

			Map<String, Object> map1 = new HashMap<String, Object>();
			map1.put("Remark", remark);
			map1.put("NoteFlag", noteflag);
			map1.put("OrderId", iorderId);

			JSONObject retBea = new ModifyremarkCall(ibuyerId, ibuyerId)
					.callAndGetReturnData(map1);
			Integer code = retBea.getInt("Code");
			String msg = retBea.getString("Msg");

			List<Ymt_O_OrderNoteHistory> ordernotes = new modifyrecipientIMapper()
					.selectiuserId(ibuyerId);
			Ymt_O_OrderNoteHistory first = ordernotes.get(0);
			String tent = first.getsContent();

			Logger.verifyEquals(200, code, "code返回结果");
			Logger.verifyEquals("操作成功", msg, "错误描述");
			Logger.verifyIsNull(tent, "备注信息为空");

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_modifyremark_006() {
		Logger.start(true, "修改备注信息--用户信息为空");
		try {

			int sellerid = 0;
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			Logger.comment("前置数据准备结束");
			int iorderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int ibuyerId = placeOrderResp.getUserId();
			String remark = "测试测试测";
			int noteflag = 1;

			Map<String, Object> map1 = new HashMap<String, Object>();
			map1.put("Remark", remark);
			map1.put("NoteFlag", noteflag);
			map1.put("OrderId", iorderId);

			JSONObject retBea = new ModifyremarkCall(sellerid, ibuyerId)
					.callAndGetReturnData(map1);
			Integer code = retBea.getInt("Code");
			String msg = retBea.getString("Msg");

			Logger.verifyEquals(201, code, "code返回结果");
			System.out.println(msg);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_modifyremark_007() {
		Logger.start(true, "修改备注信息--订单号为空");
		try {

			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			Logger.comment("前置数据准备结束");
			int ibuyerId = placeOrderResp.getUserId();
			String orderid = "null";
			String remark = "测试测试测";
			int noteflag = 1;

			Map<String, Object> map1 = new HashMap<String, Object>();
			map1.put("Remark", remark);
			map1.put("NoteFlag", noteflag);
			map1.put("OrderId", orderid);

			JSONObject retBea = new ModifyremarkCall(ibuyerId, ibuyerId)
					.callAndGetReturnData(map1);
			Integer code = retBea.getInt("Code");
			String msg = retBea.getString("Msg");

			Logger.verifyEquals(201, code, "code返回结果");
			Logger.verifyEquals("操作失败", msg, "错误描述");

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_modifyremark_008() {
		Logger.start(true, "修改备注信息--备注等级为空");
		try {

			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			Logger.comment("前置数据准备结束");
			int iorderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int ibuyerId = placeOrderResp.getUserId();
			String remark = "测试测试测";
			String noteflag = "null";

			Map<String, Object> map1 = new HashMap<String, Object>();
			map1.put("Remark", remark);
			map1.put("NoteFlag", noteflag);
			map1.put("OrderId", iorderId);

			JSONObject retBea = new ModifyremarkCall(ibuyerId, ibuyerId)
					.callAndGetReturnData(map1);
			Integer code = retBea.getInt("Code");
			String msg = retBea.getString("Msg");

			//更新订单备注信息后的SQL记录
			List<Ymt_O_OrderNoteHistory> ordernotes = new modifyrecipientIMapper()
					.selectiuserId(ibuyerId);
			Ymt_O_OrderNoteHistory first = ordernotes.get(0);
			String tent = first.getsContent();
			int user = first.getiUserId();
			int order = first.getiOrderId();

			Logger.verifyEquals(200, code, "code返回结果");
			Logger.verifyEquals("操作成功", msg, "描述");
			Logger.verifyEquals(remark, tent, "备注信息");
			Logger.verifyEquals(ibuyerId, user, "买手ID");
			Logger.verifyEquals(iorderId, order, "订单号");

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
